// pages/nianDetail/nianDetail.js
var common = require("../../public.js");
const config = require('../../config.js')
Page({

    /**
     * 页面的初始数据
     */
    data: {
        nianList:[],
        defaultHeight: "95rpx",
        listData:[
        ],
        active: 0,
        objc:{},
        id:0,
        shows:false, 
        flag:1 , //1默认展开 2不显示 3收起
        colors:'',
        typeList:[],
        showss:true,
        pagecount:1,
       totalArr:[],//分页总数据
       cardIds:"",
       productType:false,
       showes: false,
       currentPrebuy:{}, //购买须知
    },
// 底部弹出层
    showPopup(e) {
      let {
        item
      } = e.currentTarget.dataset
      console.log(item)
      this.setData({
        showes: true ,
        currentPrebuy: item,
       
      })
     
    },
// 底部弹出层
    onCloses() {
      this.setData({ showes: false });
    },

    // 查看更多  
click_data(){
  var pageCount = this.data.pagecount +1
  if(this.data.totalArr.length==pageCount){
        this.setData({
           showss:false
        })
  }
  if(this.data.totalArr[pageCount-1]){
    this.setData({
      gouList:[...this.data.gouList,...this.data.totalArr[pageCount-1]],
      pagecount:pageCount,
   })
  } 
},
click_shou(){
  this.setData({
     gouList:this.data.totalArr[0],
     showss:true,
     pagecount:1,
 })
},
  
    onClickShow(e) {
      this.setData({
         objs:e.currentTarget.dataset.item
      },()=>{
        this.setData({ show: true });
      })
    },
  
    onClickHide() {
      var that = this
      this.setData({
         show: false 
        },()=>{
          // 跳转预约界面
          wx.navigateTo({
            url: '/pages/goYuyue/yuYue/index?item=' + JSON.stringify(that.data.objs),
          })
        });
    },
    // 标签切换
    onChange(event) {

       this.cardsList(event.detail.name)

      },
      // 跳转附近场馆
      click_chuangG(){
        wx.navigateTo({
          url: '/pages/nearChangG/nearChangG',
        })    
      },
      // 跳转去预约
      click_yuYue(){
        wx.navigateTo({
          url: '/pages/goYuyue/goYuyue?id=' + this.data.objc.annualCardId,
        })    
      },
    /**
     * 生命周期函数--监听页面加载
     */
    // 权益列表
    typeList(){
      var that = this

      common.get('/store/getStoreTypeListForCard', {cardId:that.data.id}, res => {
        if (res.status === 200) {
          that.setData({
            typeList:res.data
            },()=>{
             // id
            that.cardsList(res.data[0].id)
             })
              } else {
                common.showRequestErrMsg(res)
              }

      })
    

    },
    onLoad: function (options) {
      var obj = JSON.parse(options.item)
      console.log(options)
      console.log(obj)
      var that = this
    
      that.setData({
        id:obj.annualCardId,
        objc:obj,
        productType:options.productType ? options. productType : false,
        active:options.productType ? parseInt(options.productType) :0
      },()=>{
        that.typeList() //类别列表
      })
      common.getLocalUserInfo(function (success, data) {
        if (success) {
          that.setData({
            userInfo: data.user,
            token: data.token
          }, function () {
           
          })
        } else {
          that.setData({
            userInfo: null,
            token: '',
          })
        }
    
      })

    },
    //  跳转我的订单
    click_order(){
       wx.navigateTo({
         url: '/pages/ScenicArea/ScenicAreaOrder/index',
       })
    },
    // 权益接口
    cardsList(pid){
      var that = this
  
      common.get('/userAnnualCard/getCardProductList', 
      {
        cardId:that.data.id, 
        productType:pid,
        token:that.data.token
      }, res => {
        if (res.status === 200) {
          that.setData({
                    nianList:res.data
                   },()=>{
                    var pagecount=1//默认第一页
                    var result =[]; 
                    for(var i=0,len=res.data.length;i<len;i+=3){
                      result.push(res.data.slice(i,i+3));
                   }
                   if(pagecount==1){
                    if(result[0]){
                      that.setData({
                        totalArr:result,
                        gouList:result[0],
                        pagecount:pagecount,
                        showss:true
                      })
                    }else{
                      that.setData({
                        totalArr:result,
                        gouList:[],
                        pagecount:pagecount
                      })
                    }     
                   }
                   })
                                  
        } else {
          common.showRequestErrMsg(res)
        }
    })
},

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady:function(){
      setTimeout(() => {
        this.setData({
          shows:true
        })
       }, 300);
    },


})